<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
%>

<html>
  <head>
    <title></title>
    
	<link href="<%=path%>/css/index_css.css" rel="stylesheet" type="text/css" />
	<script src="<%=path%>/js/syAjax.js" type="text/javascript"></script>
	<script src="<%=path%>/js/resizeIframe.js" type="text/javascript"></script>
	<script src="<%=path%>/dwr/engine.js"></script>
	<script src="<%=path%>/dwr/util.js"></script>
	<script src="<%=path%>/dwr/interface/shiyueDwr.js"></script>
	
	<script type="text/javascript">
window.onload   =   function(){
    	shiyueDwr.getAllYear(getAllYearCallBack);
    	resizeIframe();
    		new Anim.DD(document.getElementById("items"), document.getElementById("title"));
		document.getElementById("items").style.left = "50px";
		document.getElementById("items").style.top = "100px";
    }
    
	var objectTD;
	var objectHIDDENID;
	var orgId;
	function giveParamArr(){
		return document.getElementById(objectHIDDENID).value;
	}

	
      //显示遮罩
      function displayModuleDiv(){
		document.getElementById("items").style.display = "";	
		resizeIframe();
	}
	
	
	//关闭div
	function closeDIV(){
		document.getElementById("items").style.display = "none";
		
	}
	//年度的下拉列表框
    function getAllYearCallBack(yearMap) {
        DWRUtil.addOptions("year", yearMap);
        if('${year}'!="")
    	{
    	  document.getElementById('year').value="${year}";
    	}else if('${currentYear}'!="")
    	{
    	  document.getElementById('year').value="${currentYear}";
    	}
    } 
    
    function tdClick(url)
    {
      window.location.href=url;
    }
    
   
    
    function orgList()
    {
    	window.location.href="<%=path%>/findTeaAndDeporganizationAction.action?years=${currentYear}&orgType=2&forwardPage=teaToDepartment";
    }
    
    function staffList()
    {
    	window.location.href="<%=path%>/findCourseGroupByUserCourseAction.action?forwardPage=UserToCourse&user.userType=${sessionScope.UserInfo.userType}&years=${applicationScope.currentYear}";
    }
	
	var isEditor=1;	//是否为编辑状态 0：可编辑 1：不可编辑		
	function doChooseUser(returnStr){
		var idStr="";	
		if (returnStr == undefined) {
			return;
		}
		if (returnStr != null && returnStr != "") {
			var UserArr = returnStr.substring(0, returnStr.length - 1).split(",");
			var UserNameStr = "";
			for ( var i = 0; i < UserArr.length; i++) {
				var user = UserArr[i];
				var sonArr = user.split("_");
				if ((i + 1) % 5 == 0) {
					UserNameStr += "&nbsp;&nbsp;"+ sonArr[1]+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ "<input name=\"ppp"+orgId+"\" type=\"hidden\" value=\""+sonArr[0]+"\"/><br>";
				} else {
					UserNameStr += "&nbsp;&nbsp;"+ sonArr[1]+ "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ "<input name=\"ppp"+orgId+"\" type=\"hidden\" value=\""+sonArr[0]+"\"/>";
				}
				idStr+=sonArr[0]+",";
			}
			document.getElementById(objectHIDDENID).value=idStr;
			if (UserNameStr != "") {
				document.getElementById('div' + orgId).innerHTML = UserNameStr;
			} else {
				document.getElementById('div' + orgId).innerHTML = "";
			}
			resizeIframe();
		} else {
			document.getElementById('div' + orgId).innerHTML = "";
		}
		closeDIV();
	}
	function showModel2(obj,gradeId){
		objectTD=obj;
	  	objectHIDDENID="p"+gradeId;
	  	orgId=gradeId;
		if(document.getElementById('year').value=='${applicationScope.currentYear}')
		{
			if(isEditor==0)
	      	{
				document.getElementById("selectUserIframe").src="<%=path%>/toSelectTeacherorganizationAction.action?years=${applicationScope.currentYear}&role.roleId=member&actionURL=saveTeaAndGradeGradeAndClassAction.action&t="+ new Date();
				displayModuleDiv();
			} else {
				alert("请设为编辑状态!");
			}
		} else {
			alert("不是当前年度，不能进行此操作！");
		}

	}

	//改变编辑状态
	function changeEditor(a) {
		if (isEditor == 0) {
			a.innerHTML = "<font color='#000000'>设为编辑状态</font>";
			isEditor = 1;
		} else {
			a.innerHTML = "<font color='red'>设为非编辑状态</font>";
			isEditor = 0;
		}
	}
</script>

  </head>
  
  <body>
  <div id="contentDIV" style="position:absolute;width:100%; padding:5px; background-color:#ffffff;z-index:1;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2" align="left" class="f_5">教师分组</td>
  </tr>
  <tr>
    <td height="1" colspan="2" bgcolor="#9DD12E"></td>
  </tr>
  <tr>
    <td colspan="2" align="left" valign="top">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" align="left"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left" valign="bottom" background="images/sywesp_24.gif"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="90" align="left"><table width="90" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="1" align="left" valign="bottom" bgcolor="#CBCBCB"></td>
                <td align="center" background="images/sywesp_18.gif" class="f_6" style="cursor:pointer;" onclick="orgList();">
                  部门分组
                </td>
                <td width="1" height="31" align="right" valign="bottom" bgcolor="#CBCBCB"></td>
              </tr>
            </table></td>
            <td width="5" align="left">&nbsp;</td>
            <td width="90" align="left"><table width="90" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="1" align="left" valign="bottom" bgcolor="#CBCBCB"></td>
                <td align="center" background="images/sywesp_25.gif" class="f_9">年级分组</td>
                <td width="1" height="31" align="right" valign="bottom" bgcolor="#CBCBCB"></td>
              </tr>
            </table></td>
            <td width="5" align="left">&nbsp;</td>
            <td width="100" align="left"><table width="100" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="1" align="left" valign="bottom" bgcolor="#CBCBCB"></td>
                <td align="center" background="images/sywesp_18.gif" class="f_6" onclick="staffList();" style="cursor:pointer;">学科分组</td>
                <td width="1" height="31" align="right" valign="bottom" bgcolor="#CBCBCB"></td>
              </tr>
            </table></td>
            <td align="left">&nbsp;</td>
            </tr>
        </table></td>
      </tr>
      <tr>
        <td align="left" valign="top" class="tb_8 border_2"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td height="25" align="left" valign="middle"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="38%" align="left"><a href="findUserGradeGradeAndClassAction.action?year=${currentYear }&forwardPage=teaToGrade">按照各教师看分组</a> ┆ 按照各年级看分组 <br /></td>
                <td width="46%" align="right" valign="top">
                按年度查询：
                  <select name="select2" id="year" onchange="tdClick('<%=path%>/findUserGradeGradeAndClassAction.action?year='+this.value+'&forwardPage=gradeToTea');">
                  </select>
                </td>
                <td width="16%" style="border:solid #CCCCCC 1px;" align="right" class="f_4" onclick="changeEditor(this);" style="cursor:pointer;"><font color="#000000">设为编辑状态</font></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td align="left" valign="top">
            <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#DCDCDC">
              <tr>
                <td width="9%" height="30" bgcolor="#DBE9F6" class="f_4" align="center">年级名称</td>
                <td width="91%" bgcolor="#DBE9F6" class="f_4" align="center">姓名</td>
                </tr>
                <c:if test="${! empty gradeList}">
                <c:forEach items="${gradeList}" var="grade">
              <tr>
                <td height="30" align="center" bgcolor="#FFFFFF" class="f_4">${grade.name}<c:set value="" var="totalArr"></c:set>
                
         
                  <c:if test="${! empty UserTeaList}">
                  <td height="25" bgcolor="#FFFFFF" style="cursor:pointer;" onclick="showModel2(this,'${grade.gradeId}')" onmouseover="this.style.backgroundColor='#e4f5ff'" onmouseout="this.style.backgroundColor=''">
                  <div id="div${grade.gradeId}">
                  <%
                  	int i = 0;
                  %>
                  <c:forEach items="${UserTeaList}" var="user">
                    <c:if test="${! empty mapList}">
	                	<c:set value='${grade.gradeId}${user.userId}' var="gradeUser"></c:set>
		                	<c:if test="${! empty mapList[gradeUser]}">
		                	<c:set value="${user.userId},${totalArr}" var="totalArr"></c:set>
	                		 <%
	                		 i++;
	                		 if (i % 5 == 0) {
	                		 %>
		                	 	&nbsp;&nbsp;${user.name}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="ppp${grade.gradeId}" type="hidden" value="${user.userId}"/><br>
		                	 <%} else {%>
		                	 	&nbsp;&nbsp;${user.name}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="ppp${grade.gradeId}" type="hidden" value="${user.userId}"/>
		                	 <%}%>
                	        </c:if>
                	</c:if>
                  </c:forEach>
                  </div></td>
                  </c:if>
                  <c:if test="${empty UserTeaList}">
                     <td width="25%" align="center" height="25" style="cursor:pointer;" onclick="showModel2(this,'${grade.gradeId}')" onmouseover="this.style.backgroundColor='#e4f5ff'" onmouseout="this.style.backgroundColor=''"><div id="div${grade.gradeId}"><font color=\"red\">此年级暂无教师</font></div></td>
                  </c:if>
                  <input type="hidden" id="p${grade.gradeId}" value="${totalArr}"/>
                </tr>
                </c:forEach>
                </c:if>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
</table>
</div>
<div id="items" style="position: absolute; width: 730px;height:600px; top:100px; left:200px; padding-bottom:8px; background-color:#ECF7FD;z-index:10; border:3px solid #3A6EA5; display: none;" >
	<div style="width:100%;top:100px;left:200px;" id="title">
		<table border="0" width="100%" cellpadding="0" cellspacing="0" align="center" bgcolor="#3A6EA5">
						<tr style=" height: 30px;">
		<td>&nbsp;&nbsp;<font color='#FFFFFF'>请选择教师</font></td>
		<td align="right"><a href="javascript:closeDIV();" style="text-decoration: none;"><span style="color: #000000; font-size:;">[关闭]</span></a></td>
						</tr>
		</table>
	</div>
	<div style="width:100%;top:100px;left:200px;height: 100%">
	<iframe name="selectUserIframe" id="selectUserIframe" src="" style="width:100%;height: 100%" align="middle"  frameborder="0"></iframe>   
	</div>
		
</div>
  </body>
</html>
